﻿using Ay.Framework.WPF.Controls;
 
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Hotel.Reports;
using Hotel.Reports.Controls;

namespace Hotel.Win.Views
{
    /// <summary>
    /// VoiceCallWin.xaml 的交互逻辑
    /// </summary>
    public partial class ReportWin : AyWindow
    {
      //  private Storyboard showMain { get { return this.FindResource<Storyboard>("InviteCallMain_Show"); } }

        public ReportWin()
        {
            InitializeComponent();

            this.Opacity = 0;
            // Finding the grid that is generated by the ControlTemplate of the Button
            //var gridInTemplate = FindFrameworkElementFromTemplate("AyBackgroundBehindLayer");

            // Do something to the ControlTemplate-generated grid
            this.Loaded += this_Loaded;


            //Left = System.Windows.SystemParameters.WorkArea.Width - Width;
            //Top = System.Windows.SystemParameters.WorkArea.Height - Height;
            AyExtension.SetAyWindowMouseLeftButtonMove(this);
            tvLeftMenu.ItemsSource = CreateMenuTreeData();

        }



        private void this_Loaded(object sender2, RoutedEventArgs e2)
        {
            //showMain.Begin(this);
            reportUC.Show(@"C:\Grid++Report 6\Samples\Reports\1a.简单表格.grf", @"Provider=Microsoft.Jet.OLEDB.4.0;" +
           @"User ID=Admin;Data Source=C:\Grid++Report 6\\Samples\Data\Northwind.mdb");
        }
        public ObservableCollection<AyTreeViewItemModel> CreateMenuTreeData()
        {
            ObservableCollection<AyTreeViewItemModel> list = new ObservableCollection<AyTreeViewItemModel>();
            AyTreeViewItemModel root_0 = new AyTreeViewItemModel("前台", "fa-home", null, true);
            AyTreeViewItemModel root_01 = new AyTreeViewItemModel("多级节点1", "fa-home", root_0, true);
            AyTreeViewItemModel root_0101 = new AyTreeViewItemModel("多级节点1_1", "fa-birthday-cake", root_01, true);
            AyTreeViewItemModel root_0102 = new AyTreeViewItemModel("多级节点1_2", "fa-git", root_01, false);
            AyTreeViewItemModel root_0103 = new AyTreeViewItemModel("多级节点1_3", "fa-chain-broken", root_01, false);
            AyTreeViewItemModel root_010301 = new AyTreeViewItemModel("多级节点1_3_1", "fa-check", root_0103, false);
            AyTreeViewItemModel root_010302 = new AyTreeViewItemModel("多级节点1_3_2", "fa-check-square-o", root_0103, false);

            AyTreeViewItemModel root_02 = new AyTreeViewItemModel("多级节点2", "fa-copy", root_0, false);
            AyTreeViewItemModel root_03 = new AyTreeViewItemModel("多级节点3", "fa-comments", root_0, false);

            //AyTreeViewItemModel root = new AyTreeViewItemModel("整体Demo1", "fa-align-justify", null, true, "/Demo/MainControlPage.xaml");
            //root.IsSelected = true;

            //AyTreeViewItemModel root_1 = new AyTreeViewItemModel("整体Demo2", "fa-align-justify", null, false, "/Demo/MainControlPage2.xaml");

            AyTreeViewItemModel root0 = new AyTreeViewItemModel("财务", "fa-briefcase", null, false);
            AyTreeViewItemModel root0_1 = new AyTreeViewItemModel("AyTabControl", "fa-circle-o", root0, false, "/Reports/1a.简单表格.grf");
            AyTreeViewItemModel root0_2 = new AyTreeViewItemModel("AyWindow", "fa-circle-o", root0, false);
            AyTreeViewItemModel root0_3 = new AyTreeViewItemModel("AyPopupWindow", "fa-circle-o", root0, false);
            AyTreeViewItemModel root0_4 = new AyTreeViewItemModel("AyPanel", "fa-circle-o", root0, false);
            AyTreeViewItemModel root0_5 = new AyTreeViewItemModel("AyWrapPanel", "fa-circle-o", root0, false);
            AyTreeViewItemModel root0_7 = new AyTreeViewItemModel("AyPagePanel", "fa-circle-o", root0, false);
            AyTreeViewItemModel root0_6 = new AyTreeViewItemModel("AyRadioList", "fa-circle-o", root0, false);
            AyTreeViewItemModel root0_8 = new AyTreeViewItemModel("AyCheckList", "fa-circle-o", root0, false);

            AyTreeViewItemModel root1 = new AyTreeViewItemModel("会员", "fa_table_Solid", null, false);

            AyTreeViewItemModel root1_0 = new AyTreeViewItemModel("Button", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_9 = new AyTreeViewItemModel("ToggleButton", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_13 = new AyTreeViewItemModel("AySplitButton", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_14 = new AyTreeViewItemModel("AyComboMenu", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_15 = new AyTreeViewItemModel("AyStrokeLabel", "fa-circle-o", root1, false);

            AyTreeViewItemModel root1_12 = new AyTreeViewItemModel("AySwitch", "fa-circle-o", root1, false, "/Demo/AySwitchPage.xaml");
            AyTreeViewItemModel root1_10 = new AyTreeViewItemModel("AyImage*Button", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_11 = new AyTreeViewItemModel("AyPath", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_1 = new AyTreeViewItemModel("AyTextBox", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_2 = new AyTreeViewItemModel("AyAutoComplete", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_3 = new AyTreeViewItemModel("AyComboBox", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_4 = new AyTreeViewItemModel("AyIconAll", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_5 = new AyTreeViewItemModel("AySlider", "fa-circle-o", root1, false, "/Demo/AySliderPage.xaml");
            AyTreeViewItemModel root1_16 = new AyTreeViewItemModel("AyOpacitySetSlider", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_6 = new AyTreeViewItemModel("AyTextBox", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_7 = new AyTreeViewItemModel("AyColorPicker", "fa-circle-o", root1, false);
            AyTreeViewItemModel root1_8 = new AyTreeViewItemModel("AyColorPickerDialog", "fa-circle-o", root1, false);


            AyTreeViewItemModel root4 = new AyTreeViewItemModel("统计", "fa-list-alt", null, false);
            AyTreeViewItemModel root4_0 = new AyTreeViewItemModel("AyArcChart", "fa-circle-o", root4, false, "/Demo/AyArcChartPage.xaml");
            AyTreeViewItemModel root4_1 = new AyTreeViewItemModel("AyImageViewer", "fa-circle-o", root4, false, "/Demo/AyImageViewerPage.xaml");
            AyTreeViewItemModel root4_2 = new AyTreeViewItemModel("ShowCurrentTime", "fa-circle-o", root4, false, "/Demo/TimePage.xaml");
            AyTreeViewItemModel root4_3 = new AyTreeViewItemModel("Uc_HKControl", "fa-circle-o", root4, false, "/Demo/PieFourButtonPage.xaml");
            AyTreeViewItemModel root4_4 = new AyTreeViewItemModel("海康监控示例1", "fa-circle-o", root4, false, "/Demo/HaiKangPage.xaml");
            AyTreeViewItemModel root4_5 = new AyTreeViewItemModel("海康监控示例2", "fa-circle-o", root4, false, "/Demo/HaiKangPageLoginView.xaml");


            AyTreeViewItemModel root3 = new AyTreeViewItemModel("其他", "fa-joomla", null, false);
            AyTreeViewItemModel root3_1 = new AyTreeViewItemModel("AyTreeView", "fa-circle-o", root3, false);
            AyTreeViewItemModel root3_2 = new AyTreeViewItemModel("AySimplyListView", "fa-circle-o", root3, false, "/Demo/AySimplyListViewPage.xaml");

            AyTreeViewItemModel root5 = new AyTreeViewItemModel("版本说明", "fa-info-circle", null, false);

            list.Add(root_0);

            list.Add(root0);
            list.Add(root1);
            list.Add(root3);
            list.Add(root4);

            return list;
        }


        private void tvLeftMenu_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void TreeViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {

        }
        bool isOpenChangedMode = false;
        private void TreeViewItem_Selected(object sender, RoutedEventArgs e)
        {
            TreeViewItem tvi = e.OriginalSource as TreeViewItem;
            if (tvi != null)
            {
                AyTreeViewItemModel selectedmodel = tvi.DataContext as AyTreeViewItemModel;
                if (selectedmodel != null)
                {
                    if (selectedmodel.Depth == 0 && tvLeftMenu.AyTreeMode == IconMode.Icon && selectedmodel.ExtValue != null) //表示父节点被单击，重新设置子节点的选中状态，因为 treeviewitem的 selected会对父节点生效，导致子节点的selected效果没了
                    {
                        foreach (var item in selectedmodel.Children)//只考虑到二级
                        {
                            if (item.Text == selectedmodel.Text && item.ExtValue == selectedmodel.ExtValue)
                            {
                                item.ParentIsSelf = true;
                                break;
                            }
                        }
                    }


                    if (selectedmodel.Depth > 0 && tvLeftMenu.AyTreeMode == IconMode.Icon) //大于0代表单击的是二级，二级肯定有父节点
                    {
                        //if (!AffectQueneParentModel.Keys.Contains(selectedmodel.ParentCategory.Uid)) //记住原来的父节点
                        //{
                        //    TreeViewItemAffectModel am = new TreeViewItemAffectModel();
                        //    am.Parent = selectedmodel.ParentCategory;
                        //    am.Icon = selectedmodel.ParentCategory.Icon;
                        //    am.Text = selectedmodel.ParentCategory.Text;
                        //    am.ExtValue = selectedmodel.ParentCategory.ExtValue;
                        //    am.ExtValues = selectedmodel.ParentCategory.ExtValues;
                        //    AffectQueneParentModel[selectedmodel.ParentCategory.Uid] = am;
                        //}

                        selectedmodel.ParentCategory.Icon = selectedmodel.Icon;
                        selectedmodel.ParentCategory.Text = selectedmodel.Text;
                        selectedmodel.ParentCategory.ExtValue = selectedmodel.ExtValue;
                        selectedmodel.ParentCategory.ExtValues = selectedmodel.ExtValues;
                    }
                    else if (selectedmodel.Depth > 0 && tvLeftMenu.AyTreeMode == IconMode.IconText) //大于0代表单击的是二级，二级肯定有父节点
                    {
                        //if (!AffectQueneParentModel.Keys.Contains(selectedmodel.ParentCategory.Uid)) //父节点不受影响，只记录，当Icon模式时候，父节点的值
                        //{
                        //    TreeViewItemAffectModel am = new TreeViewItemAffectModel();
                        //    am.Parent = selectedmodel.ParentCategory;
                        //    am.Icon = selectedmodel.Icon;
                        //    am.Text = selectedmodel.Text;
                        //    am.ExtValue = selectedmodel.ExtValue;
                        //    am.ExtValues = selectedmodel.ExtValues;
                        //    AffectQueneParentModel[selectedmodel.ParentCategory.Uid] = am;
                        //}
                        //else
                        //{
                        //    var af = AffectQueneParentModel[selectedmodel.ParentCategory.Uid];
                        //    af.Icon = selectedmodel.Icon;
                        //    af.Text = selectedmodel.Text;
                        //    af.ExtValue = selectedmodel.ExtValue;
                        //    af.ExtValues = selectedmodel.ExtValues;
                        //}
                    }



                    if (selectedmodel.ExtValue == null) return;

                    #region 控制浏览器打开的逻辑
                    var tmd = selectedmodel.ExtValue.ToString();
                    if (string.IsNullOrEmpty(tmd)) return;
                    //if (tmd != lastSelectExtValue)
                    //{

                    //    if (tmd.IndexOf("http:/") == 0 || tmd.IndexOf("https:/") == 0 || tmd.IndexOf("file:/") == 0)
                    //    {
                    //        this.layoutMain.Child = null;
                    //        if (web == null)
                    //        {
                    //            web = new FormsWebBrowser(this.layoutMain, false); //或者直接this
                    //        }

                    //        web.WebBrowser.Navigate(new Uri(tmd));
                    //    }
                    //    else
                    //    {
                    //        this.layoutMain.Child = null;
                    //        if (web != null)
                    //        {
                    //            web._formCloseLock = true;
                    //            web._form.Close();
                    //            web = null;
                    //        }
                    //        Frame n = new Frame();
                    //        n.VerticalAlignment = VerticalAlignment.Stretch;
                    //        n.HorizontalAlignment = HorizontalAlignment.Stretch;
                    //        n.NavigationUIVisibility = NavigationUIVisibility.Hidden;
                    //        n.Source = new Uri(selectedmodel.ExtValue.ToString(), UriKind.Relative);
                    //        this.layoutMain.Child = n;
                    //    }
                    //    lastSelectExtValue = tmd;

                    //}
                    #endregion
                }
            }
        }

        private void tvLeftMenu_Unselected(object sender, RoutedEventArgs e)
        {

        }
        void ShowReport()
        {

            var reportForm = new ReportForm();
            WindowInteropHelper helper = new WindowInteropHelper(this);
            //reportForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            reportForm.ShowReport(helper.Handle);
        }
    }
}
